package fr.axones.pocketagile.vo
{	
	import mx.collections.ArrayCollection;

	[Bindable]
	[RemoteClass]
	public class ProjectVO
	{
		public var id:Number;
		public var name:String;
		public var profile:String;
		
		public var items:ArrayCollection;
		public var users:ArrayCollection;
		
		public function ProjectVO()
		{
		}
		
		public static function builds(s:String):ArrayCollection
		{
			var a:Array = JSON.parse(s) as Array;
			
			var ac:ArrayCollection = new ArrayCollection();
			
			for each(var o:Object in a)
			{
				ac.addItem(build_(o));
			}			
			
			return ac;
		}
		
		public static function build(s:String):ProjectVO
		{
			var o:Object = JSON.parse(s);
			
			return build_(o);
		}
		
		private static function build_(o:Object):ProjectVO
		{
			var project:ProjectVO = new ProjectVO();
			
			for (var propertyName:String in o)
			{
				if(propertyName == "items")
				{
					project.items = ProjectItemVO.builds(o[propertyName]);
				}
				else if(propertyName == "users")
				{
					project.users = UserVO.builds(o[propertyName]);
				}
				else
				{
					project[propertyName] = o[propertyName];
				}
			}
			
			return project;
		}
	}
}